package cM

import "fmt"

func dSnsExample() (s string) {
	var head = `// db2s configuration file reference
// Define source and target data sources
// Currently only supports MySQL and Oracle two data sources
`
	var p = `DSNs {
    srcDSN = "oracle|user/password@ip:port/sid"
    srcDSN = "mysql|user:password@tcp(ip:port)/information_schema"
    srcDSN = "sqlserver|server=ip addr;port=1433;user id=username;password=password;database=databaseName;charset=utf8"
    dstDSN = "cluster|user:password@tcp(ip:port)/information_schema"
}
`
	return fmt.Sprintf("%v\n%v", head, p)
}

func schemaExample(mode string) (s string) {
	switch mode {
	case "task":
		return
	default:
		return `schema {
 
	/*
		Set table objects
	*/
	table = {
		//Note: In the previous table, 1, 2, 3, 4, 5, and 6 are the order numbers for tasks. By default, the smallest and highest priority are used.
		/* Example
			1 :{include "./gtConfig/job/Create"}
			1 :{"SCHEMA"{"TABLE"{role:"role"}}}
		*/
	}
 
    /*
		Set ignored table objects
	*/
	ignore = {schema3 = ["table3"]}
 
 
	/*
		Select the object to be verified. optional value[full]
		//miss,index,
	*/
	object = full
 
	/*
		Set the merging mode of table objects, optional value[left,join,right]
	*/
	tableJoin = left
 }
`
	}
}
func taskRulesExample() (s string) {
	return `rules {
	mtc = 5
    task {
        /*
           Set the table object and enter the file name to store the table object. It is recommended to change the file to the current directory.
           The schema name and table name in the table object file are separated by commas, and can also be set to other values through limiter.
            Example:
               Requires Operation Sheet table A.B, A.C
               create object file ---> a.txt
               echo "A,B" >a.txt
               echo "A,C" >>a.txt
               =========> schema map and table not map
               Requires Operation Sheet table src [A.B] --> dst [C.B] ,
               echo "A:C,B" >>a.txt
               =========> schema not map and table map
               Requires Operation Sheet table src [A.B] --> dst [A.C],
               echo "A,B:C" >>a.txt
               =========> schema map and table map
               Requires Operation Sheet table src [A.B] --> dst [C.D],
               echo "A:C,B:D" >>a.txt
        */
        object = "fileName"
        /*
            Set the separator between the library name and table name in the table object file. By default, they are separated by commas.
        */
        limiter = ","
        /*
            Are the table object databases name, table name, and column name case-sensitive?
            case sensitive   --> true    AcA.Bcb  --> AcA.Bcb
            Not case sensitive --> false  AcA.Bcb  --> AAA.BCB
        */
        case = false
     	/*
            When the table object metadata information on the source end and the target end is inconsistent, whether to ignore the difference and take the same part.
            When set to true, only the same columns will be fetched.
            Count is not executed  --> true
            Count is executed --> false
        */
        igColumn = true
        /*
            Whether to perform count behavior on the table object of the source database when generating the specified function configuration file
            The count behavior will consume a certain amount of performance, but it will get the current number of table rows.
            Count is not executed  --> true
            Count is executed --> false
        */
        igCount = true
        /*
            Whether the session connection retains the current sql_mode when querying and writing the original target database, optional value[true,false]
            [false] ---> set sql_mode=''
        */
        sqlMode=false
        /*
            Set the indexed table to perform the histogram sampling ratio of the index column.
            Default is 30(%)  max is 100(%)
        */
        histogramScale = 30
        /*
            Set the maximum execution time of sql statement, the unit is s. If this time is exceeded, sql will commit suicide.
        */
        timeOut = 3600
        /*
            Pattern for generating configuration files
            Data online migration is configured as [sync]
            For offline data migration, the (export) configuration is [load-output], and the import configuration is [load-input].
            The check table structure is [struct]
			The check object [job,view,seq,func,procedure,type,package,trigger,foreign] is [object]
            Row-by-row data verification for the entire table is [row]
            Only verify whether the number of rows is consistent with [count]

            !! Note：Subsequent versions support partition verification, trigger verification,
            stored procedure verification, stored function verification, incremental migration,
            incremental verification and other functions. For detailed information, please view changelog.zh-CN.md
        */
        active = sync
    }
}
`
}

func syncRulesExample() (s string) {
	return `rules {	
	/*
		Set table concurrency number
	*/
	mtc = 5
	sync {
		/*
			Whether the target side should truncate table during data migration, optional value[true,false]
		*/
		truncate = false
		/*
			Whether to ignore if the target table has more columns than the source table during data migration, optional value[true,false]
		*/
		igColumn = false
		/*
			Whether the session connection retains the current sql_mode when querying and writing the original target database, optional value[true,false]
			[false] ---> set sql_mode=''
		*/
		sqlMode=false
		/*
			Whether to enable task resumption at breakpoints. After enabling it, successfully migrated tables will be automatically skipped.
			[true] -----> Skip the contents of the file result/breakPointFinish.point	
		*/
		breakpoint=false
		/*
			Whether to ignore session-level sql_log_binlog writes when writing to the data migration target, optional value[true,false]
			[true] -----> set session sql_log_bin=0 ignores binlog writing of dml statements.
			Only effective for MySQL system database
		*/
		logBin= false
		/*
			Set the consistency snapshot point. If it is 0, it means not to enable it. To enable it, it must be greater than 0.
			Limitation: 
				1) scn can only query the source side of the scope.
				2) Currently, scn is only effective for Oracle, so stay tuned for MySQL.
			get scn --> SELECT CURRENT_SCN FROM V$DATABASE;
		*/
		scn=0
		/*
		    Set whether to optimize write performance parameters on the target side.Enabling it will adjust some parameters on the target side.
		    [true]  ----> Enable writing tuning parameters
		    Only effective for MySQL system database
		*/
		paramOpt = false
		/*
			Set whether to perform analyze table behavior on the target side. Optional value[true,false]
			[true]  ----> The target side executes analyze table
			[false]  -->  The target does not execute analyze table
		*/
		analyze = true
		/*
			Whether to enable the recycle bin. Once enabled, the migration objects will be backed up and retained in the gtRecover database.Optional value[true,false]
			[true]  ----> The peer executes rename table to gtrecover.schema@table_2023040506070809
			[false]  ---> No recovery backup
		*/
		recover = true
		/*
            Set transaction execution timeout to prevent lock waiting for too long (Unit is seconds).
            If it is 0, it means not to enable it. To enable it, it must be greater than 0.
		*/
		timeOut = 3600
		/*
			Set the specified number of rows for table data migration
			[0] If it is 0 means disable, full data migration
			[>0] Greater than 0 indicates the number of rows to be migrated.
			For example:
				rowsLimit = 10  ==> Each migration object migrates 10 rows of data
		*/
		rowsLimit = 0
	}
}
`
}

func rowsRulesExample() (s string) {
	return `rules {	
	/*
		Set table concurrency number
	*/
	mtc = 5
	rows {
		/*
			Set the verification mode. optional value [crc32,md5,data]
			[CRC32] crc32 uses the crc function to generate a digital checksum and compares data differences based on the checksum.
			[MD5] md5 uses the md5 function to generate a digital checksum and compares data differences based on the checksum.
			[DATA] Directly compare the original target row data characters.
			[COUNT] 
			If crc32 or md5 mode is used and the oracle database is involved, the corresponding function needs to be created in oracle, but not for MySQL
		*/
		options = data
		/*
			Set the delay verification time in seconds, 0 means closed.
		*/
		delay= 0
		/*
			Set data character comparison rules, mostly used in heterogeneous scenarios
		*/
		rule {
			/*
				Ignore multiple trailing zero differences due to data types
			*/
			end0:true
		}
		/*
			Set the execution timeout of the program sql statement. If it is 0, it means not to open it.
		*/
		endTime = 0
    	/*
			Whether the session connection retains the current sql_mode when querying and writing the original target database, optional value[true,false]
			[false] ---> set sql_mode=''
		*/
		sqlMode=false
		/*
			Whether to enable task resumption at breakpoints. After enabling it, successfully migrated tables will be automatically skipped.
			[true] -----> Skip the contents of the file result/breakPointFinish.point	
		*/
		breakpoint=false
		/*
			Set the consistency snapshot point. If it is 0, it means not to enable it. To enable it, it must be greater than 0.
			Limitation: 
				1) scn can only query the source side of the scope.
				2) Currently, scn is only effective for Oracle, so stay tuned for MySQL.
			get scn --> SELECT CURRENT_SCN FROM V$DATABASE;
		*/
		scn=0
	}
}
`
}
func objectRulesExample() (s string) {
	return `
rules {	
	/*
		Set table concurrency number
	*/
	mtc = 5
	
	/*
		Set table concurrency number
	*/
	mtc = 5
	object {
        /*
          check table partition dataType. optional value[view,job,procedure,func,trigger,package,foreign,seq]
        */
        object = [view,job,procedure,func,trigger,package,foreign,seq,type]
		/*
			alter statement repair method, optional values [single,many]
            [single] alter table split by columns. For example:
				alter table A add column a1 int;
                alter table A add column a2 int;
            [many] alter table split by table
				alter table A add column a1 int,add column a2 int;
		*/
        alterRule = single
		/*
			Whether to enable task resumption at breakpoints. After enabling it, successfully migrated tables will be automatically skipped.
			[true] -----> Skip the contents of the file result/breakPointFinish.point		
		*/
		breakpoint=false
        /*
            Whether the session connection retains the current sql_mode when querying and writing the original target database, optional value[true,false]
            [false] ---> set sql_mode=''
        */
        sqlMode=true
		/*
			Whether to ignore session-level sql_log_binlog writes when writing to the data migration target, optional value[true,false]
			[true] -----> set session sql_log_bin=0 ignores binlog writing of dml statements.
			Only effective for MySQL system database
		*/
		logBin= false
		/*
		    Set whether to optimize write performance parameters on the target side.Enabling it will adjust some parameters on the target side.
		    [true]  ----> Enable writing tuning parameters
		    Only effective for MySQL system database
		*/
		paramOpt = false
	}
}
`
}
func structRulesExample() (s string) {
	return `rules {	
	/*
		Set table concurrency number
	*/
	mtc = 5
	struct {
		object = [column,index,partition]
        /*
          check table struct dataType
        */
		plan = {column:[name,type,null,default,comment,chart,collate],index:[]}
		/*
			alter statement repair method, optional values [single,many]
            [single] alter table split by columns. For example:
				alter table A add column a1 int;
                alter table A add column a2 int;
            [many] alter table split by table
				alter table A add column a1 int,add column a2 int;
		*/
        alterRule = single
		/*
			Whether to enable task resumption at breakpoints. After enabling it, successfully migrated tables will be automatically skipped.
			[true] -----> Skip the contents of the file result/breakPointFinish.point		
		*/
		breakpoint=false
        /*
            Whether the session connection retains the current sql_mode when querying and writing the original target database, optional value[true,false]
            [false] ---> set sql_mode=''
        */
        sqlMode=true
		/*
			Whether to ignore session-level sql_log_binlog writes when writing to the data migration target, optional value[true,false]
			[true] -----> set session sql_log_bin=0 ignores binlog writing of dml statements.
			Only effective for MySQL system database
		*/
		logBin= false
		/*
		    Set whether to optimize write performance parameters on the target side.Enabling it will adjust some parameters on the target side.
		    [true]  ----> Enable writing tuning parameters
		    Only effective for MySQL system database
		*/
		paramOpt = false
	}
}
`
}
func rulesExample(mode string) string {
	switch mode {
	case "task":
		return taskRulesExample()
	case "sync":
		return syncRulesExample()
	case "object":
		return objectRulesExample()
	case "rows":
		return rowsRulesExample()
	case "struct":
		return structRulesExample()
	default:
		return ""
	}
}
